import 'package:finance_app/generated/json/base/json_convert_content.dart';
import 'package:finance_app/generated/json/base/json_field.dart';
import 'package:finance_app/src/entities/account_entity.dart';
import 'package:finance_app/src/entities/business_contact_entity.dart';
import 'package:finance_app/src/entities/format/split_expense_entity.dart';
import 'package:finance_app/src/entities/ocr_attachment_entity.dart';
import 'package:finance_app/src/entities/payment_entity.dart';
import 'package:finance_app/src/entities/setting_data_entity.dart';
import 'package:finance_app/src/utils/cash_utils.dart';

class ExpenseDetailEntity with JsonConvert<ExpenseDetailEntity> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "contact_id")
  int contactId;
  @JSONField(name: "account_id")
  int accountId;
  BusinessContactEntity contact;
  String number;
  @JSONField(name: "issued_at")
  String issuedAt;
  List<ExpenseDetailItems> items;
  num subtotal;
  @JSONField(name: "inclusive_tax_amount")
  num inclusiveTaxAmount;
  @JSONField(name: "exclusive_tax_amount")
  num exclusiveTaxAmount;
  num total;
  num unpaid;
  @JSONField(name: "paid_using")
  String paidUsing;
  @JSONField(name: "paid_by_employee_id")
  dynamic paidByEmployeeId;
  @JSONField(name: "payment_type_id")
  int paymentTypeId;
  @JSONField(name: "reimburse_status")
  dynamic reimburseStatus;
  @JSONField(name: "reimburse_at")
  String reimburseAt;
  @JSONField(name: "rejected_reason")
  dynamic rejectedReason;
  String notes;
  String status;
  @JSONField(name: "created_by")
  dynamic createdBy;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;

  AccountEntity account;
  @JSONField(name: "currency_code")
  String currencyCode;
  List<OcrAttachmentEntity> attachments;

  @JSONField(name: "payment_type")
  SettingDataPaymentType paymentType;

  @JSONField(name: "reimburse_payment_type")
  SettingDataPaymentType reimbursePaymentType;
  @JSONField(name: "paid_by")
  String paidBy;

  @JSONField(name: "due_at")
  String dueAt;

  @JSONField(name: "is_overdue")
  int isOverdue;

  @JSONField(name: "payslip_is_pay")
  int isPayslipPaid;

  @JSONField(name: "employee_id")
  int employeeId;

  @JSONField(name: "business_contact_name")
  String businessContactName;

  List<PaymentEntity> payments;
}

class ExpenseDetailItems with JsonConvert<ExpenseDetailItems> {
  @JSONField(name: "data_type")
  String dataType;
  int id;
  @JSONField(name: "company_id")
  int companyId;
  @JSONField(name: "expense_id")
  int expenseId;
  @JSONField(name: "category_id")
  int categoryId;
  @JSONField(name: "category_key")
  String categoryKey;
  num price;
  @JSONField(name: "nett_price")
  num nettPrice;
  @JSONField(name: "is_tax_inclusive")
  int isTaxInclusive;
  @JSONField(name: "tax_amount")
  num taxAmount;
  @JSONField(name: "created_at")
  String createdAt;
  @JSONField(name: "updated_at")
  String updatedAt;

  SettingDataTax tax;
  SettingDataCategory category;

  SplitExpenseEntity toExpense() {
    return SplitExpenseEntity()
      ..selectTax = tax
      ..amount = CashUtils.formatCashAmount2(price)
      ..isCheckInclusive = isTaxInclusive == 1
      ..selectCategory = category;
  }
}
